﻿using System;
using System.Text;
using HslCommunication.BasicFramework;

namespace HslCommunication.Robot.Hyundai
{
	/// <summary>
	/// Hyundai的数据类对象
	/// </summary>
	// Token: 0x02000030 RID: 48
	public class HyundaiData
	{
		/// <summary>
		/// 实例化一个默认的对象
		/// </summary>
		// Token: 0x0600037D RID: 893 RVA: 0x0000E2BB File Offset: 0x0000C4BB
		public HyundaiData()
		{
			this.Data = new double[6];
		}

		/// <summary>
		/// 通过缓存对象实例化一个
		/// </summary>
		/// <param name="buffer"></param>
		// Token: 0x0600037E RID: 894 RVA: 0x0000E2D2 File Offset: 0x0000C4D2
		public HyundaiData(byte[] buffer)
		{
			this.LoadBy(buffer, 0);
		}

		/// <summary>
		/// 命令码，从控制器发数据到PC和PC到控制器，两者的命令不一样
		/// </summary>
		// Token: 0x1700009D RID: 157
		// (get) Token: 0x0600037F RID: 895 RVA: 0x0000E2E5 File Offset: 0x0000C4E5
		// (set) Token: 0x06000380 RID: 896 RVA: 0x0000E2ED File Offset: 0x0000C4ED
		public char Command { get; set; }

		/// <summary>
		/// 虚标记
		/// </summary>
		// Token: 0x1700009E RID: 158
		// (get) Token: 0x06000381 RID: 897 RVA: 0x0000E2F6 File Offset: 0x0000C4F6
		// (set) Token: 0x06000382 RID: 898 RVA: 0x0000E2FE File Offset: 0x0000C4FE
		public string CharDummy { get; set; }

		/// <summary>
		/// 状态码
		/// </summary>
		// Token: 0x1700009F RID: 159
		// (get) Token: 0x06000383 RID: 899 RVA: 0x0000E307 File Offset: 0x0000C507
		// (set) Token: 0x06000384 RID: 900 RVA: 0x0000E30F File Offset: 0x0000C50F
		public int State { get; set; }

		/// <summary>
		/// 标记数据，从PLC发送给机器人的数据，原封不动的返回
		/// </summary>
		// Token: 0x170000A0 RID: 160
		// (get) Token: 0x06000385 RID: 901 RVA: 0x0000E318 File Offset: 0x0000C518
		// (set) Token: 0x06000386 RID: 902 RVA: 0x0000E320 File Offset: 0x0000C520
		public int Count { get; set; }

		/// <summary>
		/// 虚标记
		/// </summary>
		// Token: 0x170000A1 RID: 161
		// (get) Token: 0x06000387 RID: 903 RVA: 0x0000E329 File Offset: 0x0000C529
		// (set) Token: 0x06000388 RID: 904 RVA: 0x0000E331 File Offset: 0x0000C531
		public int IntDummy { get; set; }

		/// <summary>
		/// 关节坐标数据，包含X,Y,Z,W,P,R，三个位置数据，三个角度数据。
		/// </summary>
		// Token: 0x170000A2 RID: 162
		// (get) Token: 0x06000389 RID: 905 RVA: 0x0000E33A File Offset: 0x0000C53A
		// (set) Token: 0x0600038A RID: 906 RVA: 0x0000E342 File Offset: 0x0000C542
		public double[] Data { get; set; }

		/// <summary>
		/// 从字节数组的指定索引开始加载现在机器人的数据
		/// </summary>
		/// <param name="buffer">原始的字节数据</param>
		/// <param name="index">起始的索引信息</param>
		// Token: 0x0600038B RID: 907 RVA: 0x0000E34C File Offset: 0x0000C54C
		public void LoadBy(byte[] buffer, int index = 0)
		{
			this.Command = (char)buffer[index];
			this.CharDummy = Encoding.ASCII.GetString(buffer, index + 1, 3);
			this.State = BitConverter.ToInt32(buffer, index + 4);
			this.Count = BitConverter.ToInt32(buffer, index + 8);
			this.IntDummy = BitConverter.ToInt32(buffer, index + 12);
			this.Data = new double[6];
			for (int i = 0; i < this.Data.Length; i++)
			{
				bool flag = i < 3;
				if (flag)
				{
					this.Data[i] = BitConverter.ToDouble(buffer, index + 16 + 8 * i) * 1000.0;
				}
				else
				{
					this.Data[i] = BitConverter.ToDouble(buffer, index + 16 + 8 * i) * 180.0 / 3.141592653589793;
				}
			}
		}

		/// <summary>
		/// 将现代机器人的数据转换为字节数组
		/// </summary>
		/// <returns>字节数组</returns>
		// Token: 0x0600038C RID: 908 RVA: 0x0000E428 File Offset: 0x0000C628
		public byte[] ToBytes()
		{
			byte[] array = new byte[64];
			array[0] = (byte)this.Command;
			bool flag = !string.IsNullOrEmpty(this.CharDummy);
			if (flag)
			{
				Encoding.ASCII.GetBytes(this.CharDummy).CopyTo(array, 1);
			}
			BitConverter.GetBytes(this.State).CopyTo(array, 4);
			BitConverter.GetBytes(this.Count).CopyTo(array, 8);
			BitConverter.GetBytes(this.IntDummy).CopyTo(array, 12);
			for (int i = 0; i < this.Data.Length; i++)
			{
				bool flag2 = i < 3;
				if (flag2)
				{
					BitConverter.GetBytes(this.Data[i] / 1000.0).CopyTo(array, 16 + 8 * i);
				}
				else
				{
					BitConverter.GetBytes(this.Data[i] * 3.141592653589793 / 180.0).CopyTo(array, 16 + 8 * i);
				}
			}
			return array;
		}

		/// <inheritdoc />
		// Token: 0x0600038D RID: 909 RVA: 0x0000E52C File Offset: 0x0000C72C
		public override string ToString()
		{
			return string.Format("HyundaiData:Cmd[{0},{1},{2},{3},{4}] Data:{5}", new object[]
			{
				this.Command,
				this.CharDummy,
				this.State,
				this.Count,
				this.IntDummy,
				SoftBasic.ArrayFormat<double>(this.Data)
			});
		}
	}
}
